home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 3 / csmp-digest-v3-132 < prev    next >
Text File  |  1996-01-18  |  56KB  |  1,562 lines

  1. C.S.M.P. Digest             Thu, 18 Jan 96       Volume 3 : Issue 132
  2.  
  3. Today's Topics:
  4.  
  5.         FYI: Web page with info on devloping MacOS Lotus Notes apps
  6.         How do I do ZoomRects?
  7.         How do I make finder show new contents of folder?
  8.         How to get default user name
  9.         Monitor Numbering
  10.         Restoring the Color Environment
  11.         Sprite Collision detection
  12.         char *pixel access; SwapMMUmode?
  13.  
  14.  
  15.  
  16. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  17. (pottier@clipper.ens.fr).
  18.  
  19. The digest is a collection of article threads from the internet
  20. newsgroups comp.sys.mac.programmer.help, csmp.tools, csmp.misc and
  21. csmp.games. It is designed for people who read news semi-regularly and
  22. want an archive of the discussions.  If you don't know what a
  23. newsgroup is, you probably don't have access to it. Ask your systems
  24. administrator(s) for details. If you don't have access to news, you
  25. may still be able to post messages to the group by using a mail server
  26. like anon.penet.fi (mail help@anon.penet.fi for more information).
  27.  
  28. Each issue of the digest contains one or more sets of articles (called
  29. threads), with each set corresponding to a 'discussion' of a particular
  30. subject.  The articles are not edited; all articles included in this digest
  31. are in their original posted form (as received by our news server at
  32. nef.ens.fr).  Article threads are not added to the digest until the last
  33. article added to the thread is at least two weeks old (this is to ensure that
  34. the thread is dead before adding it to the digest).  Article threads that
  35. consist of only one message are generally not included in the digest.
  36.  
  37. The digest is officially distributed by two means, by email and ftp.
  38.  
  39. If you want to receive the digest by mail, send email to listserv@ens.fr
  40. with no subject and one of the following commands as body:
  41.     help                                Sends you a summary of commands
  42.     subscribe csmp-digest Your Name     Adds you to the mailing list
  43.     signoff csmp-digest                 Removes you from the list
  44. Once you have subscribed, you will automatically receive each new
  45. issue as it is created.
  46.  
  47. The official ftp info is ftp://ftp.dartmouth.edu/pub/csmp-digest.
  48. Questions related to the ftp site should be directed to
  49. scott.silver@dartmouth.edu.
  50.  
  51. -------------------------------------------------------
  52.  
  53. >From gansler@boardwalk.tiac.net (Rick Gansler)
  54. Subject: FYI: Web page with info on devloping MacOS Lotus Notes apps
  55. Date: Wed, 03 Jan 1996 16:35:52 -0500
  56. Organization: Boardwalk Software
  57.  
  58. I just posted a page with about 40k of text about the Lotus Notes C API,
  59. from the perspective of a Mac developer.
  60.  
  61. Please feel free to browse it and distribute the link.
  62.  
  63. http://www.tiac.net/users/gansler/notes/notes.html
  64.  
  65. -- 
  66.                                                   ___
  67. Rick Gansler, Boardwalk Software                 |   \
  68. Mac & Windows Software Development & Consulting  |___/o a r d w a l k
  69. gansler@boardwalk.tiac.net                   ====|===\=================
  70. http://www.tiac.net/users/gansler/               |___/   software
  71.  
  72. ---------------------------
  73.  
  74. >From timmyd@netcom.com (Tim DeBenedictis)
  75. Subject: How do I do ZoomRects?
  76. Date: Tue, 2 Jan 1996 20:38:10 GMT
  77. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  78.  
  79. How do I implement a ZoomRect (a thin gray rectangle that "zooms out" when
  80. a window opens or closes, as when you open one of the Finder's directory
  81. windows)?  Is there a built-in Toolbox trap to do this already?
  82.  
  83. -Tim DeBenedictis
  84. timmyd@netcom.com
  85.  
  86.  
  87. +++++++++++++++++++++++++++
  88.  
  89. >From larry_kearney@appsig.com (Lawrence Kearney)
  90. Date: Tue, 02 Jan 1996 14:53:36 -0700
  91. Organization: Applied Signal Technology
  92.  
  93. In article <timmydDKKMnM.47L@netcom.com>, timmyd@netcom.com (Tim
  94. DeBenedictis) wrote:
  95.  
  96. > How do I implement a ZoomRect (a thin gray rectangle that "zooms out" when
  97. > a window opens or closes, as when you open one of the Finder's directory
  98. > windows)?  Is there a built-in Toolbox trap to do this already?
  99.  
  100. Try looking in the book Macintosh Programming Secrets.  I found a copy of
  101. all the source code in the book on the net somewhere but I don't remember
  102. exactly where. It was in the file "MPS disk V1.0.1". The code can be found
  103. in chapter 7.
  104.  
  105. -- 
  106. Larry Kearney                   |   "You want fries with that?"
  107. Applied Signal Technology       |
  108. larry_kearney@appsig.com        |
  109.  
  110. +++++++++++++++++++++++++++
  111.  
  112. >From David Reiss <reiss@astro.washington.edu>
  113. Date: 3 Jan 1996 02:10:47 GMT
  114. Organization: http://www.astro.washington.edu
  115.  
  116. Also, look into the drag manager.  There's a nice little trap, ZoomRects,
  117. I think it's called.  It does just this.  But you need the Drag Manager
  118. for it to work.
  119.  
  120. There's also sample code for this on Apple's web server.
  121.  
  122. -David
  123.  
  124.  
  125. +++++++++++++++++++++++++++
  126.  
  127. >From kenlong@netcom.com (Ken Long)
  128. Date: Wed, 3 Jan 1996 02:16:21 GMT
  129. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  130.  
  131. Lawrence Kearney (larry_kearney@appsig.com) wrote:
  132. : In article <timmydDKKMnM.47L@netcom.com>, timmyd@netcom.com (Tim
  133. : DeBenedictis) wrote:
  134.  
  135. : > How do I implement a ZoomRect (a thin gray rectangle that "zooms out" when
  136. : > a window opens or closes, as when you open one of the Finder's directory
  137. : > windows)?  Is there a built-in Toolbox trap to do this already?
  138.  
  139. Also, get "MyCard" and/or "MyNewCard" off ftp AmbrosiaSW.com 
  140. /pub/alt.sources.mac/alt.sources.mac
  141.  
  142. About volume6 or 7 (?).  There's an index there, too.
  143.  
  144. -Ken-
  145.  
  146. +++++++++++++++++++++++++++
  147.  
  148. >From erichsen@pacificnet.net (Erichsen)
  149. Date: Tue, 02 Jan 1996 23:47:04 -0800
  150. Organization: Disorganized
  151.  
  152. In article <larry_kearney-0201961453360001@kearneymac.appsig.com>,
  153. larry_kearney@appsig.com (Lawrence Kearney) wrote:
  154.  
  155. > How do I implement a ZoomRect (a thin gray rectangle that "zooms out" when
  156. > a window opens or closes, as when you open one of the Finder's directory
  157. > windows)?  Is there a built-in Toolbox trap to do this already?
  158.  
  159. If you've got the Drag Manager installed, there's two routines, ZoomRects
  160. and ZoomRegion that do just what you want. If you want to know how to do
  161. it, read Mac Programming Secrets as someone else already suggested.
  162.  
  163. ---------------------------
  164.  
  165. >From torl@oslonett.no (Tor Langballe)
  166. Subject: How do I make finder show new contents of folder?
  167. Date: 28 Dec 1995 18:12:44 GMT
  168. Organization: Cutting Edge
  169.  
  170. My application copies files to a folder and changes files names.
  171. Unfortunatly the changes aren't immediatly visible in the finder, I have
  172. to close, then open the folder to see the changer. How can I force this to
  173. happen?
  174.  
  175. I've tried changing the folders modification date with the following code,
  176. but it didn't help:
  177.  
  178. bool ForceFinderToUpdateFileIcon(const char *filename)
  179. {
  180.   long       dirID;
  181.   short      volref;
  182.   CInfoPBRec tempPB;
  183.    
  184.   if(GetDirectoryID(filename, &dirID, &volref)) // (from full path)
  185.   {
  186.     tempPB.dirInfo.ioNamePtr = 0L;
  187.     tempPB.dirInfo.ioVRefNum = volref;
  188.     tempPB.dirInfo.ioFDirIndex = -1;
  189.     tempPB.dirInfo.ioDrDirID = dirID;
  190.  
  191.     if(PBGetCatInfoSync(&tempPB) == noErr) 
  192.     {
  193.       tempPB.dirInfo.ioDrMdDat = LMGetTime();
  194.       tempPB.dirInfo.ioDrDirID = dirID;
  195.       return PBSetCatInfoSync(&tempPB) == noErr;
  196.     }
  197.   }
  198.   
  199.   return FALSE; 
  200. }
  201.  
  202. thanks,
  203.  
  204. Tor Langballe
  205.  
  206. Tor Langballe
  207. Cutting Edge Technologies
  208. Norway
  209.  
  210. +++++++++++++++++++++++++++
  211.  
  212. >From jumplong@aol.com (Jump Long)
  213. Date: 29 Dec 1995 01:17:17 -0500
  214. Organization: America Online, Inc. (1-800-827-6364)
  215.  
  216. Tor Langballe wrote:
  217. >My application copies files to a folder and changes files names.
  218. >Unfortunatly the changes aren't immediatly visible in the
  219. >finder, I have to close, then open the folder to see the
  220. >changer. How can I force this to happen?
  221.  
  222. The most reliable way to force the Finder to notice your changes is to
  223. tell it to "update" using the scriptable Finder. You can find code that
  224. shows how to do that with the article "Scripting the Finder From Your
  225. Application" by Greg Anderson in develop magazine issue #20 (probably
  226. available at
  227. ftp://ftp.info.apple.com/Apple.Support.Area/Developer_Services/Periodicals
  228. /develop/develop20/ if I were to guess the URL).
  229.  
  230. If the scriptable Finder isn't available (check with Gestalt, the
  231. gestaltFinderAttr selecter, looking at the gestaltOSLCompliantFinder bit),
  232. then you can use BumpDate or FSpBumpDate from the MoreFiles sample code to
  233. touch the modification date of the file's parent directory. Touching a
  234. directory's modification date will make the Finder notice your changes
  235. most, but not all, of the time.
  236.  
  237. - Jim Luther
  238.  
  239. +++++++++++++++++++++++++++
  240.  
  241. >From kenlong@netcom.com (Ken Long)
  242. Date: Fri, 29 Dec 1995 17:11:58 GMT
  243. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  244.  
  245. Tor Langballe (torl@oslonett.no) wrote:
  246. : My application copies files to a folder and changes files names.
  247. : Unfortunatly the changes aren't immediatly visible in the finder, I have
  248. : to close, then open the folder to see the changer. How can I force this to
  249. : happen?
  250.  
  251. get "ctc 1.6" and look at the "tickle" routine.  As I recall, it's for 
  252. the purpose of making the Finder take notice of changes in its turf.
  253.  
  254. -Ken-
  255.  
  256. +++++++++++++++++++++++++++
  257.  
  258. >From Jeff Pritchard <jeffp@inow.com>
  259. Date: Wed, 03 Jan 1996 19:11:18 -0700
  260. Organization: NSI/INOW
  261.  
  262. Tor Langballe wrote:
  263. > My application copies files to a folder and changes files names.
  264. > Unfortunatly the changes aren't immediatly visible in the finder, I have
  265. > to close, then open the folder to see the changer. How can I force this to
  266. > happen?
  267. > I've tried changing the folders modification date with the following code,
  268. > but it didn't help:
  269.  
  270.  
  271. This is a tricky one in some cases.  If all you are doing is what you say above, 
  272. then sending an update event to the Finder should do what you need. Try something 
  273. like this (the fsspec has the parent dir ID of the directory you changed and the 
  274. name of the dir you changed):
  275.  
  276. void SendUpdateAppleEvent(FSSpec *directory)
  277.         {
  278.         AppleEvent                              the_apple_event;
  279.         AEAddressDesc                   target_address;
  280.         AppleEvent                              theAEReply = {typeChar, nil};
  281.         AESendMode                              theSendMode = kAENoReply;
  282.         OSErr                                   error;
  283.         ProcessSerialNumber     tempPSN;
  284.         OSErr                                   myErr = noErr;
  285.         ProcessInfoRec                  infoRecToFill;
  286.         OSType                                  typeToFind = 'FNDR';            // the finders type and creator
  287.         OSType                                  creatorToFind = 'MACS';
  288.         unsigned char                   name[32];
  289.         FSSpec                                  spec;
  290.         
  291.         tempPSN.lowLongOfPSN = kNoProcess;
  292.         tempPSN.highLongOfPSN = kNoProcess;
  293.         infoRecToFill.processInfoLength = sizeof(ProcessInfoRec);
  294.         infoRecToFill.processName = name;
  295.         infoRecToFill.processAppSpec = &spec;
  296.  
  297.         do      {
  298.                 myErr =  GetNextProcess(&tempPSN);
  299.                 
  300.                 if(myErr == noErr)
  301.                         GetProcessInformation(&tempPSN,&infoRecToFill);
  302.  
  303.                 } while(((infoRecToFill.processSignature != creatorToFind) || 
  304.                          (infoRecToFill.processType != typeToFind) ) &&  (myErr == noErr));
  305.                          
  306.         if(myErr != noErr)
  307.                 return;                         // abject failure, give up in disgust
  308.         
  309.         error = AECreateDesc(typeProcessSerialNumber, &tempPSN,
  310.                                                 sizeof(ProcessSerialNumber), &target_address);
  311.         
  312.         if(!error)
  313.                 {
  314.  
  315.                 error = AECreateAppleEvent('fndr', 'fupd',
  316.                                                                                 &target_address,
  317.                                                                                 kAutoGenerateReturnID,
  318.                                                                                 kAnyTransactionID,
  319.                                                                                 &the_apple_event);
  320.  
  321.                 if(!error)
  322.                         {
  323.                         error = 
  324. AEPutParamPtr(&the_apple_event,keyDirectObject,typeFSS,directory,sizeof(FSSpec));
  325.                         
  326.                         if(!error)
  327.                                 {       
  328.                 
  329.                                 error = AESend(&the_apple_event, &theAEReply, theSendMode,
  330.                                                                 kAENormalPriority, kAEDefaultTimeout, nil, nil);
  331.                                                                 
  332.                                 AEDisposeDesc(&the_apple_event);
  333.                                 AEDisposeDesc(&theAEReply);
  334.                                 }
  335.                         }
  336.                         
  337.                 AEDisposeDesc(&target_address);
  338.                 }
  339.  
  340.         }
  341.  
  342.  
  343. In my case, I was changing some other things that the Finder wouldn't update with 
  344. this simple approach.  In particular, I was changing a file from a real file to an 
  345. alias file with the same name.  The only way I have found that works is really 
  346. weird!  You have to move the file to the trash (programatically), and then send a 
  347. "putaway" command to the Finder.  This puts the file back where it belongs, and 
  348. does update EVERYTHING   about the file in the process.  Hopefully you won't have 
  349. to go to these extremes!
  350.  
  351. +++++++++++++++++++++++++++
  352.  
  353. >From jim@interaxus.com (Jim Friedlander)
  354. Date: Wed, 03 Jan 1996 21:02:07 -0800
  355. Organization: Interaxus
  356.  
  357. In article <30EB3746.1324@inow.com>, jeffp@inow.com wrote:
  358.  
  359. > Tor Langballe wrote:
  360. > > 
  361. > > My application copies files to a folder and changes files names.
  362. > > Unfortunatly the changes aren't immediatly visible in the finder, I have
  363. > > to close, then open the folder to see the changer. How can I force this to
  364. > > happen?
  365. > > 
  366. > > I've tried changing the folders modification date with the following code,
  367. > > but it didn't help:
  368. > This is a tricky one in some cases.  If all you are doing is what you
  369. say above, 
  370. > then sending an update event to the Finder should do what you need. Try
  371. something 
  372. > like this (the fsspec has the parent dir ID of the directory you changed
  373. and the 
  374. <<<<snip>>>>>
  375.  
  376. or, you can use the following routine to simply change the modification
  377. date of the folder the file is in...it works for me :)
  378.  
  379. jim 
  380.  
  381.  
  382. /*
  383.    This routine is used to force the Finder (as much as is possible) to update
  384.    information about a newly changed file or folder.  
  385.    It does this by changing the modification date of the surrounding folder.
  386. */
  387. OSErr ForceFinderUpdate(FSSpec *pFSS, Boolean flush)
  388. {
  389.    OSErr       lErr;
  390.    CInfoPBRec     lCBlk;
  391.    
  392.    if (pFSS->parID != 1)   // if it's a vol then reuse the NameStr
  393.       lCBlk.dirInfo.ioNamePtr = 0L;
  394.    lCBlk.dirInfo.ioVRefNum = pFSS->vRefNum;     
  395.    lCBlk.dirInfo.ioDrDirID = pFSS->parID;
  396.    lCBlk.dirInfo.ioFDirIndex = 0;
  397.    lCBlk.dirInfo.ioCompletion = 0;
  398.  
  399.    lErr = PBGetCatInfoSync(&lCBlk);
  400.    if (!lErr) {
  401.       GetDateTime(&lCBlk.dirInfo.ioDrMdDat);
  402.       lCBlk.dirInfo.ioDrDirID = pFSS->parID;
  403.       lErr = PBSetCatInfoSync(&lCBlk);
  404.    
  405.       if ((!lErr) && (flush))
  406.          lErr = FlushVol(nil, pFSS->vRefNum);
  407.    }
  408.    
  409.    return (lErr);
  410. }
  411.  
  412. + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
  413. |              Jim Friedlander   *   jim@interaxus.com            |
  414. |                     <http://www.interaxus.com>                  |
  415. |                                                                 |
  416. |           A hamburger by any other name is more expensive       |
  417. + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
  418.  
  419. ---------------------------
  420.  
  421. >From alam@cs.umn.edu (Haseen I. Alam)
  422. Subject: How to get default user name
  423. Date: 29 Dec 1995 06:41:06 GMT
  424. Organization: University of Minnesota
  425.  
  426.  
  427.  Hello:
  428.  
  429.  I am trying to write a small external routine in C to get the default user
  430.  name set in the Sharing Control Panel.  I tried the function GetDefaultUser
  431.  using the following code fragmant in Symentec C++, but I get the following
  432.  result Error# -923, Ref# 28012900, Name: , According to Think Reference,
  433.  -923 is noLoggedInErr, meaning Default user reference number does not 'yet'
  434.  exist.  I do have my name in the owner name field.  I am clueless!
  435.  
  436.  I would greatly apprecite any help with this issue.  Thanks in advance.
  437.  (PS: please e-mail your responses.)
  438.  
  439.  -- Haseen
  440.  
  441.  
  442.     #include <stdio.h>
  443.     #include <stdlib.h>
  444.     #include <PPCToolbox.h>
  445.     #include <Types.h>
  446.  
  447.     int main()
  448.     {
  449.         int iErr;
  450.         unsigned long * userRef;
  451.         Str32 userName;
  452.         iErr = GetDefaultUser(userRef,userName);
  453.         printf("Error# %d, Ref# %d, Name: %s,\n",iErr, userRef,userName);
  454.         return EXIT_SUCCESS;
  455.     }
  456.  
  457.  .------------------------------------------------------------------------.
  458.  | Haseen I. Alam   (612) 544-3274  | "If you think I am expensive, wait  |
  459.  | email: alam@cs.umn.edu           |     till you hire an amateur!"      |
  460.  `------------------------------------------------------------------------'
  461.  
  462. +++++++++++++++++++++++++++
  463.  
  464. >From mhteas@btech.com (Malcolm H. Teas)
  465. Date: 29 Dec 1995 15:25:21 GMT
  466. Organization: Blaze Technology, Inc.
  467.  
  468. There's a system string resource with the ID of -167xx. (Don't remember
  469. the last few digits.)  This holds the name of the owner of the Mac. 
  470. This name is set in the Owner Name field in the Sharing Setup control
  471. panel.
  472.  
  473. Malcolm  H. Teas                E-Mail: mhteas@btech.com
  474. Blaze Technology, Inc.          Telephone: 512/502-9552
  475. PO Box 200279                   Fax: 512/502-9554
  476. Austin, TX USA 78720-0279
  477.    ** A Macintosh software development services company  **
  478.  
  479. +++++++++++++++++++++++++++
  480.  
  481. >From jumplong@aol.com (Jump Long)
  482. Date: 30 Dec 1995 15:43:10 -0500
  483. Organization: America Online, Inc. (1-800-827-6364)
  484.  
  485. Haseen I. Alam wrote:
  486. >I am trying to write a small external routine in C to get the
  487. >default user name set in the Sharing Control Panel.  I tried the
  488. >function GetDefaultUser using the following code fragmant in
  489. >Symentec C++, but I get the following result Error# -923, Ref#
  490. >28012900, Name: , According to Think Reference, -923 is
  491. >noLoggedInErr, meaning Default user reference number does not
  492. >'yet' exist.  I do have my name in the owner name field.  I am
  493. >clueless!
  494.  
  495. GetDefaultUser is a PPC Toolbox routine that returns the default PPC user
  496. reference number and user name *after* the user has used the name and
  497. password entered in the Sharing Setup control panel to authenticate
  498. themselves to a remote system. Until the user has done that,
  499. GetDefaultUser will return noLoggedInErr (-923).
  500.  
  501. What you really want to do is use GetString to get a handle to 'STR '
  502. resource -16096 like this:
  503.  
  504. StringHandle userNameHandle;
  505. Str255       userName;
  506. /* Get the user name and make a copy of it. */
  507. /* Don't release or dispose of the system resource handle. */
  508. userNameHandle = GetString(-16096);
  509. BlockMove(*userNameHandle, &userName, *userNameHandle[0]+1);
  510.  
  511. - Jim Luther
  512.  
  513. ---------------------------
  514.  
  515. >From jonpugh@netcom.com (Jon Pugh)
  516. Subject: Monitor Numbering
  517. Date: Sat, 30 Dec 1995 18:57:27 GMT
  518. Organization: Will hack for food
  519.  
  520. I'm making my screen list scripting addition return an index for the monitors
  521. and I would like it to match the numbers that the Monitors cdev puts up
  522. when you press Identify.  My first attempt, which numbered them from the 
  523. first GDevice in the list and up, turned out wrong, but given that I only
  524. have two monitors, I don't have a nearly big enough sample to determine if
  525. it's simply the reverse of that or what.  Does anyone know how the cdev 
  526. numbers them?  I suppose it's into the code editor to see how it's done if
  527. no one knows.  ;)
  528.  
  529. Also, does anyone remember the name of the routine which changes the 
  530. resolution? I think it's in QuickTime 2.1, but didn't see it on a fast 
  531. look at the includes included.
  532.  
  533. Jon
  534.  
  535.  
  536. +++++++++++++++++++++++++++
  537.  
  538. >From Matt Slot <fprefect@umich.edu>
  539. Date: 30 Dec 1995 23:14:43 GMT
  540. Organization: University of Michigan
  541.  
  542. Jon Pugh, jonpugh@netcom.com writes:
  543. > Also, does anyone remember the name of the routine which changes the 
  544. > resolution? I think it's in QuickTime 2.1, but didn't see it on a fast 
  545. > look at the includes included.
  546.  
  547. I found such information in the Display Manager SDK, which is typically 
  548. found at the following URL (however, it seems to be down over the holiday
  549. weekedn).
  550.  
  551.    <ftp://ftp.info.apple.com/Apple.Support.Area/Developer_Services/
  552.         System_Software_Extensions/Display_Manager_Development_Kit/
  553.         Display_Manager_Developmen.sit.hqx>
  554.  
  555. Matt
  556.  
  557. * * * * * * * * * * * * * * * * * * * * * * * * * * ======================
  558. *  Reality: Matt Slot                             *  Time is an illusion.
  559. *  E-Mail:  mailto:fprefect@umich.edu             *  Lunchtime doubly so.
  560. *  Web:     http://www.sils.umich.edu/~fprefect/  *     -- Douglas Adams
  561. * * * * * * * * * * * * * * * * * * * * * * * * * * ======================
  562.  
  563. +++++++++++++++++++++++++++
  564.  
  565. >From joviansoft@aol.com (JovianSoft)
  566. Date: 31 Dec 1995 07:12:28 -0500
  567. Organization: America Online, Inc. (1-800-827-6364)
  568.  
  569. >Also, does anyone remember the name of the routine which changes the 
  570. >resolution? I think it's in QuickTime 2.1, but didn't see it on a fast 
  571. >look at the includes included.
  572.  
  573. Volume VI of Inside Mac has the following routines to get depth info &
  574. change it:
  575.  
  576. HasDepth()  
  577. SetDepth()
  578.  
  579. It's in the Graphics Device Manager section.
  580.  
  581. Hope this helps (HTH)
  582.  
  583.  
  584. +++++++++++++++++++++++++++
  585.  
  586. >From johnb@tempest.net.hk (John W. Blackburne)
  587. Date: 01 Jan 1996 06:58:03 GMT
  588. Organization: Tempest, Hong Kong
  589.  
  590. Jon Pugh,jonpugh@netcom.com, wrote:
  591. > I'm making my screen list scripting addition return an index for the
  592. monitors
  593. > and I would like it to match the numbers that the Monitors cdev puts up
  594. > when you press Identify.  My first attempt, which numbered them from the 
  595. > first GDevice in the list and up, turned out wrong, but given that I only
  596. > have two monitors, I don't have a nearly big enough sample to determine if
  597. > it's simply the reverse of that or what.  Does anyone know how the cdev 
  598. > numbers them?  I suppose it's into the code editor to see how it's done if
  599. > no one knows.  ;)
  600.  
  601. I think it's a hardware ordering, sensed at startup or wake up. I don't
  602. really have much evidence to support this, as I'm only going by the way my
  603. 6100av works, but I also remember that many Macs can check NuBus slot
  604. ordering for video devices, even if the Mac doesn't have NuBus slots: E.g. I
  605. remember the 165c's internal and external video had a virtual NuBus slot for
  606. each device. The 'scrn' resource (documented in IM V) has slot numbering info
  607. for devices.
  608.  
  609. This may not work on PowerMacs, as they all require the Display Manager,
  610. which replaces the old Slot Manager way of doing things. In particular the
  611. latest Macs with PCI probably have no need for NuBus emulation. But I'm
  612. mostly guessing here - apart from the Display Manager SDK docs this is all
  613. very poorly documented, and there's nothing anywhere on Monitor CDEV device
  614. numberings.
  615.  
  616. I looked at this for my screennmode OSAX, but the only way I could see to do
  617. it was by walking the display list using GetMainDevice and GetNextDevice and
  618. using this as an ordering. This is OK for two displays but the order is
  619. unpredictable for more, and changes if the user changes main device at any
  620. time. Another way would be to use their locations to number them from left to
  621. right, but this fails with some display arrangements and again changes as the
  622. user moves things around.
  623.  
  624. > Also, does anyone remember the name of the routine which changes the 
  625. > resolution? I think it's in QuickTime 2.1, but didn't see it on a fast 
  626. > look at the includes included.
  627.  
  628. AFAIK the only way documented and only way compatible with the latest
  629. machines is through the Display Manager API.
  630.  
  631. John
  632. --
  633. John Blackburne:        johnb@tempest.net.hk, jwb@eworld.com
  634. Programmer, Asia, Inc. Online:       http://www.asia-inc.com
  635. Consultant, trainer & writer: http://www.hk.super.net/~johnb
  636.  
  637. ---------------------------
  638.  
  639. >From Paul Czarnecki <pZ@Customline.com>
  640. Subject: Restoring the Color Environment
  641. Date: Tue, 2 Jan 1996 03:51:42 GMT
  642. Organization: Customline Software
  643.  
  644. I am writing a program which displays images with custom
  645. palettes.  I am using the palette manager, CW7.
  646.  
  647. When I close my window, the default palette isn't restored. 
  648. I am making this call
  649.  
  650. SetPalette((WindowPtr) aWin, nil, true);
  651. ActivatePalette((WindowPtr) aWin);
  652.  
  653. before I close my window.  But nothing happens.
  654.  
  655. Now IM is a little unclear here, I don't know if you are
  656. allowed to pass nil to SetPalette.  Is is ok?
  657.  
  658. I guess I could get the default system ones, but which one I
  659. choose?  The deepest monitor?  The one the window I am
  660. closing is on?  The menu bar one?  What should I do if I
  661. span monitors?
  662.  
  663. Thanks!
  664.  
  665. pZ
  666. --  
  667. Paul Czarnecki -- Customline Software
  668. Macintosh Contract Programming -- Imaging -- Internet
  669. MacApp -- PowerPlant -- C/C++ -- HTML
  670. pZ@Customline.com -- http://www.artsys.com/ner
  671.  
  672. +++++++++++++++++++++++++++
  673.  
  674. >From "Andrew C. Plotkin" <erkyrath+@CMU.EDU>
  675. Date: Tue,  2 Jan 1996 12:13:54 -0500
  676. Organization: Carnegie Mellon, Pittsburgh, PA
  677.  
  678. Paul Czarnecki <pZ@Customline.com> writes:
  679. > I am writing a program which displays images with custom
  680. > palettes.  I am using the palette manager, CW7.
  681. > When I close my window, the default palette isn't restored. 
  682. >
  683. > I guess I could get the default system ones, but which one I
  684. > choose?  The deepest monitor?  The one the window I am
  685. > closing is on?  The menu bar one?  What should I do if I
  686. > span monitors?
  687.  
  688. If you'll look at your Palette Manager chapter of NIM: Color Imaging
  689. (I don't know if that's out on dead trees, but it's on FTP and develop
  690. CDs)...
  691.  
  692. RestoreDeviceClut (GDHandle gdh);
  693.  
  694. will return the given monitor to its default colors. You can probably
  695. use DeviceLoop or something to go through and do this to each monitor
  696. that your window touches.
  697.  
  698. --Z
  699.  
  700. "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
  701.  
  702. +++++++++++++++++++++++++++
  703.  
  704. >From Paul Czarnecki <pZ@Customline.com>
  705. Date: Wed, 3 Jan 1996 03:51:32 GMT
  706. Organization: Customline Software
  707.  
  708. >When I close my window, the default palette isn't restored. 
  709. >I am making this call
  710. >
  711. >SetPalette((WindowPtr) aWin, nil, true);
  712. >ActivatePalette((WindowPtr) aWin);
  713. >
  714. >before I close my window.  But nothing happens.
  715. >
  716. >Now IM is a little unclear here, I don't know if you are
  717. >allowed to pass nil to SetPalette.  Is is ok?
  718.  
  719. Doing this works.
  720.  
  721.         RestoreDeviceClut(nil);
  722.         SetPalette((WindowPtr) mMacWindowP, nil, true);
  723.         ActivatePalette((WindowPtr) mMacWindowP);
  724.  
  725. It's curious, that doing just this:
  726.  
  727.         RestoreDeviceClut(nil);
  728.  
  729. or just these:
  730.  
  731.         RestoreDeviceClut(nil);
  732.         ActivatePalette((WindowPtr) mMacWindowP);
  733.  
  734. do not work.  In both cases, the palette is sucessfully
  735. restored (I had the Monitors Control Panel to watch my
  736. palette) but Finder's window's were still messed up.  In the
  737. first case, the colors didn't change at all, in the 2nd
  738. case, they changed, but to an odd set, even though the
  739. palette was correct.  Making all three calls is the
  740. solution.
  741.  
  742. pZ
  743. --  
  744. Paul Czarnecki -- Customline Software
  745. Macintosh Contract Programming -- Imaging -- Internet
  746. MacApp -- PowerPlant -- C/C++ -- HTML
  747. pZ@Customline.com -- http://www.artsys.com/ner
  748.  
  749. ---------------------------
  750.  
  751. >From erayzal@iway.fr (Emmanuel Rayzal)
  752. Subject: Sprite Collision detection
  753. Date: Wed, 13 Dec 1995 18:14:25 +0200
  754. Organization: Internet-Way
  755.  
  756. For my first game, I'm using encoded sprites as described in Chapter 3
  757. "Advanced Graphics" of Tricks of the Mac Game Programming Gurus.
  758.  
  759. I need pixel level collision detection, but I don't see any simple and
  760. elegant way to do this with encoded sprites. I wonder if I shouldn't
  761. generate bitmaped masks just for collision detection.
  762.  
  763.  
  764.  
  765. Any suggestions ?
  766.  
  767. Emmanuel
  768.  
  769. +++++++++++++++++++++++++++
  770.  
  771. >From elliott@mpi-muelheim.mpg.de (Mark Elliott)
  772. Date: 14 Dec 1995 08:53:52 GMT
  773. Organization: Max-Planck-Institut f. Kohlenforsch. Muelheim
  774.  
  775. In article <erayzal-1312951814250001@ts2-p30.dialup.iway.fr>,
  776. erayzal@iway.fr (Emmanuel Rayzal) wrote:
  777.  
  778. > For my first game, I'm using encoded sprites as described in Chapter 3
  779. > "Advanced Graphics" of Tricks of the Mac Game Programming Gurus.
  780. > I need pixel level collision detection, but I don't see any simple and
  781. > elegant way to do this with encoded sprites. I wonder if I shouldn't
  782. > generate bitmaped masks just for collision detection.
  783. > Any suggestions ?
  784.  
  785. I do not use encoded sprites, but I see no reason for this technique not
  786. to work. What I do is first to check my sprite list for a likely collision
  787. (i.e. the Rects of my enemy sprite and my player sprite overlap). I then
  788. have a collision detection GWorld where I draw my enemy sprites. Next I
  789. 'draw' my player sprite, but instead of drawing the pixels I do something
  790. like
  791.  
  792. if ((*player | *dest) != (*player & *dest)) collision = true;
  793.  
  794. (check the logic - this is just off the top of my head).
  795.  
  796. I guess this is not the fastest way, but I can't think of a faster way of
  797. doing true pixel level collision detection. I suppose for each line of
  798. each sprite you could have values stored for the left/right limits of the
  799. sprite, but this would not be 100% safe if you have gaps in the middle of
  800. your sprite.
  801.  
  802. nb. The pointers are to longs, so this method checks 4 pixels at a time. I
  803. also make sure that I am only checking the absolute minimum number of
  804. sprites (usually only one or two per frame).
  805.  
  806. If you need more info/specific code, let me know.
  807.  
  808. regards
  809.  
  810. Mark
  811.  
  812. - ------------------------------------------------------------------
  813. Mark C Elliott                           elliott@mpi-muelheim.mpg.de
  814. Max-Planck-Institut                      voice: (+49) 208 306 2429
  815. Fuer Kohlenforschung
  816. Muelheim, Germany
  817. - ------------------------------------------------------------------
  818.  
  819. +++++++++++++++++++++++++++
  820.  
  821. >From mick@emf.net (Mick Foley)
  822. Date: Wed, 13 Dec 1995 22:11:30 -0800
  823. Organization: "emf.net" Quality Internet Access.  (510) 704-2929 (Voice)
  824.  
  825. In article <erayzal-1312951814250001@ts2-p30.dialup.iway.fr>,
  826. erayzal@iway.fr (Emmanuel Rayzal) wrote:
  827.  
  828. > For my first game, I'm using encoded sprites as described in Chapter 3
  829. > "Advanced Graphics" of Tricks of the Mac Game Programming Gurus.
  830. > I need pixel level collision detection, but I don't see any simple and
  831. > elegant way to do this with encoded sprites. I wonder if I shouldn't
  832. > generate bitmaped masks just for collision detection.
  833. > Any suggestions ?
  834. > Emmanuel
  835.  
  836. Hey there --
  837.  
  838. There are several possible approaches to collision detection:
  839.  
  840. 1. Rects. This is the simplest and the fastest. Assign a rect that
  841. approximates the size and shape of the sprite and check with these. Even
  842. if you don't use this for final checks, checking for collisions with
  843. bounding rects will eliminated all the trivial cases quicky.
  844.  
  845. 2. Multiple rects. Instead of one rectangle, store several rects whose
  846. union defines the shape of the sprite.
  847.  
  848. 3. Circles. Store a midpoint and radius for each spite. To determine the
  849. collision check if the distance between the two midpoints is less than the
  850. sum of the radii. (Skip the square root -- check to see if the sqare of
  851. the distance is less than the square of the sum of the radii).
  852.  
  853. 4. Spans. Modify the encoder so that is stores a start and end point for
  854. each scan line of the shape. Then check if these spans collide. Works
  855. great for convex shapes w/o holes.
  856.  
  857. 5. Bitmaps. Store a bitmap of each shape and check the collision this way.
  858. It will give you the best accuaracy, but the slowest check.
  859.  
  860. For very simple shapes I would use a combination of 1,2 and 3. For complex
  861. shapes I would use 4. I think that 5 is only needed in rare cases.
  862.  
  863. Just my thouhgts --
  864.  
  865. Mick
  866.  
  867. +++++++++++++++++++++++++++
  868.  
  869. >From gordon@micron.net (Gordon Henriksen)
  870. Date: 22 Dec 1995 17:15:17 GMT
  871. Organization: Micron Internet Services
  872.  
  873. In article <erayzal-1312951814250001@ts2-p30.dialup.iway.fr>,
  874. erayzal@iway.fr (Emmanuel Rayzal) wrote:
  875.  
  876. > For my first game, I'm using encoded sprites as described in Chapter 3
  877. > "Advanced Graphics" of Tricks of the Mac Game Programming Gurus.
  878.  
  879. > I need pixel level collision detection, but I don't see any simple and
  880. > elegant way to do this with encoded sprites. I wonder if I shouldn't
  881. > generate bitmaped masks just for collision detection.
  882.  
  883. > Any suggestions ?
  884.  
  885. Well, yes. I don't see an elegant way to do collision detection through
  886. run length encoded (RLE) sprites either. RLE accelerates the drawing
  887. process to much to give up, so, if I may, I would like to suggest that you
  888. maintain both the RLE data AND a bitmap collision mask. This is more
  889. flexible because, often the drawing mask does not produce desirable
  890. results for collision detection.
  891.  
  892. There is a significant amount of information on collision detection at
  893. <x2ftp.oulu.fi:/pub/msdos/programming/> much of it is only theory, so it
  894. is cross platform.
  895.  
  896.                       TTFN,
  897.                         Gordon Henriksen
  898.                         gordon@micron.net
  899.  
  900. +++++++++++++++++++++++++++
  901.  
  902. >From Bernie Wieser <octavian@agt.net>
  903. Date: 27 Dec 1995 22:16:32 GMT
  904. Organization: Octavian Micro Development Inc.
  905.  
  906. On the Macintosh, you can do something which is quite simple,
  907. but not too portable that handles pixel collision.
  908.  
  909. The basic form is this; you have a bitmap (not a pixmap) that you
  910. can convert to a region.  Then just call
  911. the toolbox on the regions for intersection.
  912. This means your sprite object has a region,
  913. but you can dispose of your bitmap once you've
  914. got the region.
  915.  
  916. B.
  917.  
  918.  
  919.  
  920.  
  921. +++++++++++++++++++++++++++
  922.  
  923. >From zzkbergm@dingo.uq.edu.au (Christoph Bergmann)
  924. Date: Fri, 29 Dec 1995 00:38:53 +1000
  925. Organization: University of Queensland
  926.  
  927. In article <4bsgk0$6bb@news.agt.net>, Bernie Wieser <octavian@agt.net> wrote:
  928.  
  929. > On the Macintosh, you can do something which is quite simple,
  930. > but not too portable that handles pixel collision.
  931. > The basic form is this; you have a bitmap (not a pixmap) that you
  932. > can convert to a region.  Then just call
  933. > the toolbox on the regions for intersection.
  934. > This means your sprite object has a region,
  935. > but you can dispose of your bitmap once you've
  936. > got the region.
  937. > B.
  938.  
  939. yeah, is good and simple. and slow.
  940. way too slow for any fast-paced game (unless of course u have a faster ppc...)
  941. good method for a slow moving game tho..
  942.  
  943. +++++++++++++++++++++++++++
  944.  
  945. >From dangit@netcom.com (Lam Dang)
  946. Date: Thu, 28 Dec 1995 16:28:18 GMT
  947. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  948.  
  949.  
  950. Yah, the combination of RLE for drawing, and 1-bit mask work best;
  951. it does tkae a bit more memory, but hey, not much.  (besides, how big
  952. are your sprites gonna be?).
  953.  
  954. But I got a question now; how are people handling sprites larger than
  955. 32 pixels?  a long is only 32 pixels, so...  multiple banks?  Hmm.
  956. bitshifting would be a pain...
  957.  
  958. Also, instead of checking each line, skipping lines also works, as long
  959. as you don't have sprites 2 pixels tall..  (depending on how many lines
  960. you skip.  (this wouldn't really save too much time, would it?  bit &'s
  961. are fast.)
  962.  
  963. -Jimmy Dang, BlairHS Senior
  964.  jdang@mbhs.edu
  965.  
  966. -- 
  967. Lam Dang
  968. dangit@netcom.com
  969.  
  970.                                 
  971.  
  972. +++++++++++++++++++++++++++
  973.  
  974. >From jmunkki@beta.hut.fi (Juri Munkki)
  975. Date: 28 Dec 1995 19:00:49 GMT
  976. Organization: Helsinki University of Technology
  977.  
  978. In article <4bsgk0$6bb@news.agt.net> Bernie Wieser <octavian@agt.net> writes:
  979. >The basic form is this; you have a bitmap (not a pixmap) that you
  980. >can convert to a region.  Then just call
  981. >the toolbox on the regions for intersection.
  982. >This means your sprite object has a region,
  983. >but you can dispose of your bitmap once you've
  984. >got the region.
  985.  
  986. Regions are not particularly fast for this kind of work. Inside
  987. Macintosh has the incorrect statement that OffsetRegion is fast: it is
  988. not as fast as they claim. I think the reason it says that might be
  989. that the implementation used to be different, but was later changed
  990. (before 1984).
  991.  
  992. -- 
  993. Juri Munkki jmunkki@iki.fi              Life is easy when polygons are cheap.
  994. http://www.iki.fi/~jmunkki                 Windsurfing: Faster than the wind.
  995.  
  996. +++++++++++++++++++++++++++
  997.  
  998. >From Bernie Wieser <octavian@agt.net>
  999. Date: 29 Dec 1995 19:24:09 GMT
  1000. Organization: Octavian Micro Development Inc.
  1001.  
  1002. I don't have a problem with it being slow...
  1003. because I only call it when sprite bounding
  1004. rects intersect, and in most situations where
  1005. I use it, there are never more than 4 collisions
  1006. possible.  It's not a problem.
  1007.  
  1008. B.
  1009.  
  1010.  
  1011.  
  1012.  
  1013. +++++++++++++++++++++++++++
  1014.  
  1015. >From erayzal@iway.fr (Emmanuel Rayzal)
  1016. Date: Fri, 29 Dec 1995 22:15:49 +0200
  1017. Organization: Internet-Way
  1018.  
  1019. Hi !
  1020.  
  1021. I'm the original poster of this thread. I've thinking a little bit and I
  1022. have now
  1023. a fast solution. 
  1024.  
  1025. So, I use RLE for drawing, and RLE for collision detection (after checking that 
  1026. boundrects intersects).
  1027.  
  1028. The source code is just here. (based on RLE as described in chapter 3 of 
  1029. "Tricks of the Mac Game Programming Gurus")
  1030.  
  1031. The function Check Collision takes as parameters the 2 sprites, and the offset
  1032.  
  1033. The function GetNextRun search the next run of pixels for a sprite (line,
  1034. beginning
  1035. (left) and length). Returns false when no more pixels to draw.
  1036.  
  1037. I've a faster version with no function call for GetNextRun. I didn't
  1038. include it because it's really unreadable, just ask.   
  1039.  
  1040.  
  1041. /********** CheckCollision *********/
  1042. // offset = pos2 - pos1
  1043.  
  1044. Boolean CheckCollision(tSpriteInfo *sprite1,tSpriteInfo *sprite2, Point offset)
  1045. {
  1046.     unsigned char *ptr1 = (unsigned char *)((*(sprite1->fSpriteData))
  1047.                                         + sizeof(Rect));
  1048.     unsigned char *ptr2 = (unsigned char *)((*(sprite2->fSpriteData))
  1049.                                         + sizeof(Rect));
  1050.     
  1051.     short line1,line2;  // current line number for both sprites
  1052.     
  1053.     short start1,start2,length1,length2,start1bis;
  1054.     
  1055.     line1 = line2 = start1 = start2 = 0;
  1056.  
  1057.     line1 += offset.v; 
  1058.  
  1059.     // Get first run of each sprite
  1060.  
  1061.     if (GetNextRun(&ptr1,&line1,&start1,&length1) == 0)
  1062.         return false;
  1063.     if (GetNextRun(&ptr2,&line2,&start2,&length2) == 0)
  1064.         return false;
  1065.     
  1066.     while (1)
  1067.     {
  1068.         if (line1 == line2) // got a run on matching line
  1069.         {
  1070.             start1bis = start1 + offset.h;
  1071.             
  1072.             if (start1bis < start2) // 1 begins before 2
  1073.             {
  1074.                 if (start2 < start1bis +length1)    // 2 begins before 1's end ?
  1075.                     return true;        // yes -> collision
  1076.                 else if (GetNextRun(&ptr1,&line1,&start1,&length1) ==
  1077. 0)    // no -> next r1
  1078.                     return false;
  1079.             }
  1080.             else if (start1bis > start2)
  1081.             {
  1082.                 if (start1bis < start2 + length2)   // 1 begins before 2's end ?
  1083.                     return true;    // yes -> collision
  1084.                 else if (GetNextRun(&ptr2,&line2,&start2,&length2) ==
  1085. 0)    // no -> next r2    
  1086.                     return false;
  1087.             }
  1088.             else // if (start1+offset.h == start2)
  1089.                 return true;    // I assume there's no empty runs
  1090.             
  1091.         }
  1092.         else if (line1 > line2) // got a run on non matching lines
  1093.         {
  1094.             if (GetNextRun(&ptr2,&line2,&start2,&length2) == 0)
  1095.                 return false;
  1096.         }
  1097.         else // if (line1 + offset.v < line2)
  1098.         {
  1099.             if (GetNextRun(&ptr1,&line1,&start1,&length1) == 0)
  1100.                 return false;
  1101.         
  1102.         }
  1103.     }
  1104.     return false;       // end of (one) sprite - still no collision 
  1105. }
  1106.  
  1107.  
  1108. /********** GetNextRun *********/
  1109. // call it first with *line = 0, *start = 0
  1110.  
  1111. Boolean GetNextRun(unsigned char **srcPtr,short *line,short *start,short
  1112. *length)
  1113. {       
  1114.     unsigned long tokenOp;          // the op code from the token
  1115.     unsigned long tokenData;        // the data from the token
  1116.  
  1117.     while (true)
  1118.     {
  1119.         tokenOp = ( *( ( unsigned long * )(*srcPtr) ) ) >> 24;
  1120.         tokenData = ( *( ( unsigned long * )(*srcPtr) ) ) & 0x00ffffff;
  1121.         
  1122.         switch(tokenOp)
  1123.         {
  1124.             case kLineStartToken:   // new line
  1125.                     (*line) ++;         // increment line (Line Feed)
  1126.                     (*start) = 0;       // Carriage return :-)
  1127.                     (*srcPtr) += sizeof (unsigned long *);  // skip instruction
  1128.                     break;
  1129.  
  1130.             case kDrawPixelsToken:              // ok, we have the run
  1131.                     (*srcPtr) += (sizeof (unsigned long *)     // skip
  1132. instruction 
  1133.                                     + tokenData     // skip data
  1134.                                     +  (( ( tokenData & 3L ) == 0 ) ? 0 :
  1135. ( 4 - ( tokenData & 3L ) ))); // padding
  1136.                     (*length) = tokenData;
  1137.                     return true;
  1138.                     break;
  1139.                     
  1140.             case kSkipPixelsToken:
  1141.                     (*start) += tokenData;              // increment start
  1142.                     (*srcPtr) += sizeof (unsigned long *);  // skip instruction
  1143.                     break;
  1144.                     
  1145.             case kEndShapeToken:
  1146.                     return false;       // end of sprite, no run found
  1147.                     break;
  1148.  
  1149.             default:
  1150.                     // we should never get here
  1151.                     DebugStr("\pGetNextRun - unknown token");
  1152.         }
  1153.     }
  1154. }
  1155.  
  1156. - -
  1157. Emmanuel Rayzal
  1158.  
  1159. +++++++++++++++++++++++++++
  1160.  
  1161. >From hnsngr@sirius.com (Ron Hunsinger)
  1162. Date: Mon, 01 Jan 1996 00:21:04 -0800
  1163. Organization: ErsteSoft
  1164.  
  1165. In article <4buph1$bid@nntp.hut.fi>, jmunkki@beta.hut.fi (Juri Munkki) wrote:
  1166.  
  1167. > In article <4bsgk0$6bb@news.agt.net> Bernie Wieser <octavian@agt.net> writes:
  1168. > >The basic form is this; you have a bitmap (not a pixmap) that you
  1169. > >can convert to a region.  Then just call
  1170. > >the toolbox on the regions for intersection.
  1171. > >This means your sprite object has a region,
  1172. > >but you can dispose of your bitmap once you've
  1173. > >got the region.
  1174. > Regions are not particularly fast for this kind of work. Inside
  1175. > Macintosh has the incorrect statement that OffsetRegion is fast: it is
  1176. > not as fast as they claim. I think the reason it says that might be
  1177. > that the implementation used to be different, but was later changed
  1178. > (before 1984).
  1179.  
  1180. I think you're right about that.
  1181.  
  1182. Specifically, the reason they give for why it's supposed to be fast is
  1183. that "most of the data defining a region is stored relative to rgnBBox and
  1184. so isn't actually changed by OffsetRgn." That turns out to be untrue. In
  1185. fact, NOTHING in a region's data is based on rgnBBox (except for rgnBBox
  1186. itself, of course).
  1187.  
  1188. It could have been. It's a trifling change in (the interpretation of) the
  1189. data structure. So either the implementation changed after they told the
  1190. manual writers it was fast, or they planned to change it to make OffsetRgn
  1191. fast and never got around to it.
  1192.  
  1193. In any event, a Region is basically a RLE representation, so any RLE-base
  1194. algorithm should have similar run time. If you already have RLE sprites,
  1195. it shouldn't be hard to write your own collision detection routine that
  1196. runs directly off the RLE data, and still beats OffsetRgn+SectRgn handily,
  1197. because your routine won't have to do the OffsetRgn, AND it won't have to
  1198. actually produce a region representing the intersection.
  1199.  
  1200. -Ron Hunsinger
  1201.  
  1202. ---------------------------
  1203.  
  1204. >From dangit@netcom.com (Lam Dang)
  1205. Subject: char *pixel access; SwapMMUmode?
  1206. Date: Tue, 26 Dec 1995 04:23:04 GMT
  1207. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1208.  
  1209. In all of the sample code I've seen, I see:
  1210.  
  1211. Byte mode=true32b;
  1212. SwapMMUMode(&mode);
  1213. // pixel access (of pixmap, screen (heaven forbid), whatever)
  1214. SwapMMUMode(&mode);
  1215.  
  1216. For my wonderful scroller engine, I've done the same; however, I'm curious;
  1217. why is this neccessary?  I'd experiment, but I don't have a mac right now.
  1218. (Chrismas vacation.. anyone wanna lend me a mac?)  I'd look it up, but I 
  1219. don't have Inside mac.  :P.
  1220.  
  1221. Also, more random questions;
  1222.         -Which is faster, memcpy() or BlockMove()?  Equivalent?
  1223.         -Does MacTCP support nonblocking calls?  (Dynamic client connections)
  1224.         -Is it at all feasible to synchronize to the vertical retrace?
  1225.          (To get rid of shearing)
  1226.         -What is the maximum theoretical FPS for blitting large areas?
  1227.          (e.g. 256x256, 512x512, etc.. also non 2^n areas, like 304x304)
  1228.          (Need to have a goal to aim for)
  1229.         -How about drawing every other scanline?  (for direct screen access)
  1230.          (Yes, I KNOW direct screen is taboo, but rest assured, I plan to
  1231.           make it an option)
  1232.         -What are the disadvantages of not using an event loop?
  1233.          (i.e. using only MouseLoc, GetKeys, etc.)
  1234.         -There is a nonblocking event checker, right?
  1235.         -I'm CopyBits-ing direct to the screen; is this alright, or should
  1236.          I be using some weird type of window that covers the entire screen?
  1237.  
  1238. -Jimmy Dang, Blair HS Senior
  1239.  jdang@mbhs.edu
  1240.  "This message is 100% Phat Phree."  (sorry hh).
  1241.  
  1242. PS Oh yeah, Merry <insert fav holiday here>.
  1243. -- 
  1244. Lam Dang
  1245. dangit@netcom.com
  1246.  
  1247.                                 
  1248.  
  1249. +++++++++++++++++++++++++++
  1250.  
  1251. >From "Andrew C. Plotkin" <erkyrath+@CMU.EDU>
  1252. Date: Tue, 26 Dec 1995 23:16:06 -0500
  1253. Organization: Carnegie Mellon, Pittsburgh, PA
  1254.  
  1255. dangit@netcom.com (Lam Dang) writes:
  1256. > In all of the sample code I've seen, I see:
  1257. > Byte mode=true32b;
  1258. > SwapMMUMode(&mode);
  1259. > // pixel access (of pixmap, screen (heaven forbid), whatever)
  1260. > SwapMMUMode(&mode);
  1261. > For my wonderful scroller engine, I've done the same; however, I'm curious;
  1262. > why is this neccessary?  
  1263.  
  1264. As I understand it, it's because the video memory may not be in a
  1265. space accessible with a 24-bit address. But please don't quote me,
  1266. because I'm not sure. 
  1267.  
  1268. >   -Which is faster, memcpy() or BlockMove()?  Equivalent?
  1269.  
  1270. BlockMove will always be as fast as possible on whatever Mac it's
  1271. running on. (Except that you may want to call BlockMoveData instead,
  1272. if you're not copying executable code. The only difference is that
  1273. BlockMoveData doesn't clear the instruction cache.) memcpy may just
  1274. call BlockMove, but if it doesn't, it's probably slower. 
  1275.  
  1276. >   -Does MacTCP support nonblocking calls?  (Dynamic client
  1277. connections)
  1278.  
  1279. Sorry, dunno.
  1280.  
  1281. >   -Is it at all feasible to synchronize to the vertical retrace?
  1282. >    (To get rid of shearing)
  1283.  
  1284. It's possible in simple cases, but it can get arbitrarily complicated.
  1285. I don't think most games bother, and I've never complained about
  1286. shearing problems, so... don't bother.
  1287.  
  1288. >   -What is the maximum theoretical FPS for blitting large areas?
  1289. >    (e.g. 256x256, 512x512, etc.. also non 2^n areas, like 304x304)
  1290. >    (Need to have a goal to aim for)
  1291.  
  1292. Depends heavily on the CPU and video hardware. Of course! 
  1293.  
  1294. The goal to aim for is (of course) beating CopyBits. If you can't do
  1295. that, well, you know what conclusion to draw.
  1296.  
  1297. >   -How about drawing every other scanline?  (for direct screen access)
  1298. >    (Yes, I KNOW direct screen is taboo, but rest assured, I plan to
  1299. >     make it an option)
  1300.  
  1301. Twice the previous answer.
  1302.  
  1303. >   -What are the disadvantages of not using an event loop?
  1304. >    (i.e. using only MouseLoc, GetKeys, etc.)
  1305.  
  1306. Background apps don't execute. The menu bar clock doesn't update
  1307. (assuming your game leaves the menu bar visible.) Nobody complains
  1308. much about this during the game itself; people seem to be resigned to
  1309. the fact that they can't play Marathon during long FTP sessions. But,
  1310. of course, you should have a normal event loop for menu screens and
  1311. the game-pause screen. 
  1312.  
  1313. Also, do you mean GetMouse? I can't find "MouseLoc"; if it's a
  1314. low-memory global, you should avoid it.
  1315.  
  1316. >   -There is a nonblocking event checker, right?
  1317.  
  1318. GetNextEvent. I'm told it's a little slower if there is no pending
  1319. event, so it helps to send yourself an event before calling
  1320. GetNextEvent. But I've never verified or tried this. 
  1321.  
  1322. Last time I wrote a high-speed game, I used GetMouse and GetKeys and
  1323. ignored events entirely. But I had to flush key and mouse events
  1324. before returning to the menu event loop.
  1325.  
  1326. >   -I'm CopyBits-ing direct to the screen; is this alright, or should
  1327. >    I be using some weird type of window that covers the entire screen?
  1328.  
  1329. Oh, god, please use a window that covers the entire screen. (Nothing
  1330. weird about it; just pick the window style that has a one-pixel
  1331. border.) This doesn't cost any speed, it costs minimal memory
  1332. (NewWindow etc don't allocate very much at all), and everybody will be
  1333. happier if you don't mess with the root GrafPort. 
  1334.  
  1335. Besides, then you can provide a running-in-a-regular-window mode for
  1336. people who want it. And it's easier to move to different monitors. And
  1337. you can get sensible mouse events in your menu event loop. And, in
  1338. fact, why the heck aren't you doing this already?
  1339.  
  1340. --Z
  1341.  
  1342. "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
  1343.  
  1344. +++++++++++++++++++++++++++
  1345.  
  1346. >From pottier@drakkar.ens.fr (Francois Pottier)
  1347. Date: 27 Dec 1995 12:57:02 GMT
  1348. Organization: Ecole Normale Superieure, Paris
  1349.  
  1350. In article <dangitDK6EuH.34I@netcom.com>, Lam Dang <dangit@netcom.com> wrote:
  1351. >In all of the sample code I've seen, I see:
  1352.  
  1353. >For my wonderful scroller engine, I've done the same; however, I'm curious;
  1354. >why is this neccessary?
  1355.  
  1356. This is because the pixel map data might be located inside a NuBus video
  1357. card instead of residing in main memory. Accessing memory on these cards
  1358. might require switching to 32 bit mode if the processor is in 24 bit mode,
  1359. because they have fixed, high addresses which are too large to fit into
  1360. a 24 bit pointer.
  1361.  
  1362. Be aware that SwapMMUMode is slow, that you need to always restore the
  1363. previous mode carefully, and that you can't make any System/Toolbox
  1364. calls while the mode is swapped.
  1365.  
  1366. You can avoid using SwapMMUMode in several cases:
  1367.  
  1368.  - if you know the Mac is currently in 32 bit mode, which is always
  1369.    true on Power Macs.
  1370.  
  1371. or
  1372.  
  1373.  - if the pixel map you are trying to access has been created by
  1374.    calling NewGWorld with the keepLocal flag set. This flag tells
  1375.    QuickDraw not to allocate memory inside a video card. It can be
  1376.    slower because some accelerated cards are designed to carry their
  1377.    own memory which they can access quickly, but at least it makes
  1378.    your life simpler.
  1379.  
  1380. I have applied these rules and stayed out of trouble until now,
  1381. so I think they're correct. Someone please correct me if I'm wrong.
  1382.  
  1383. >       -Which is faster, memcpy() or BlockMove()?  Equivalent?
  1384.  
  1385. On a particular machine, I don't know, but if you use BlockMove
  1386. you'll win because it's in ROM and it is optimized for the very
  1387. machine it is on, so it'll generally beat memcpy.
  1388.  
  1389. >       -I'm CopyBits-ing direct to the screen; is this alright, or should
  1390. >        I be using some weird type of window that covers the entire screen?
  1391.  
  1392. Hide the menu bar and use a window. This way, an update event
  1393. will be generated for other apps when you close the window.
  1394.  
  1395. Hope this helps,
  1396.  
  1397.  
  1398.  
  1399. -- 
  1400. Francois
  1401. pottier@dmi.ens.fr
  1402. http://www.eleves.ens.fr:8080/home/pottier/
  1403.  
  1404. +++++++++++++++++++++++++++
  1405.  
  1406. >From cameron_esfahani@powertalk.apple.com (Cameron Esfahani)
  1407. Date: Wed, 27 Dec 1995 16:15:15 -0800
  1408. Organization: Apple Computer, Inc.
  1409.  
  1410. Beware of calling BlockMove or BlockMoveData to copy from your own
  1411. offscreen buffer to the screen directly.  BlockMove/BlockMoveData is
  1412. optimized for source and destination to both be cacheable.  IO space is
  1413. noncacheable, so you will get an multiple access faults for each call.  Of
  1414. course the operating system will hide this from you, you just will have a
  1415. really really slow transfer rate.
  1416.  
  1417. If you are copying to/from uncacheable memory, use
  1418. BlockMoveUncached/BlockMoveDataUncached.  These calls, I believe, are
  1419. implemented in System 7.5.2 and later.
  1420.  
  1421. Cameron Esfahani
  1422.  
  1423. +++++++++++++++++++++++++++
  1424.  
  1425. >From Hiep Dam <starlabs@loop.com>
  1426. Date: Sun, 31 Dec 1995 01:21:24 -0700
  1427. Organization: From The Witches' Brew
  1428.  
  1429. Lam Dang wrote:
  1430. > In all of the sample code I've seen, I see:
  1431. > Byte mode=true32b;
  1432. > SwapMMUMode(&mode);
  1433. > // pixel access (of pixmap, screen (heaven forbid), whatever)
  1434. > SwapMMUMode(&mode);
  1435. > For my wonderful scroller engine, I've done the same; however, I'm curious;
  1436. > why is this neccessary?  I'd experiment, but I don't have a mac right now.
  1437. > (Chrismas vacation.. anyone wanna lend me a mac?)  I'd look it up, but I
  1438. > don't have Inside mac.  :P.
  1439.  
  1440. >From my understanding (which may or may not be 100% correct ^_^):
  1441. You need to use SwapMMUMode in the case that your computer is running 
  1442. under 24-bit addressing mode [heaven forbid!]. Due to the way video 
  1443. memory may be located on VRAM or a video card, access here is always 
  1444. 32-bit. So you have to switch to 32-bit addressing in order to access 
  1445. video memory. Trying to access vram while under 24-bit addressing 
  1446. might give you bogus values.
  1447.  
  1448. My opinion is don't bother with it. I've written plenty of blitters 
  1449. which pretty much omit this - they assume they're running under 32-bit 
  1450. addressing. It's pretty rare these days to find a Mac that's NOT 
  1451. running under 32-bit addressing. As an added bonus, IT'S MUCH 
  1452. FASTER!!! Yes, I checked. I ran my blitters under 24-bit addressing 
  1453. mode (where they had to use SwapMMUMode) and under 32-bit addressing. 
  1454. The difference was significant, around 10%-30% faster under 32-bit 
  1455. addressing. Sorry I can't remember the exact figures... Probably due 
  1456. to less overhead in calling the 2 SwapMMUMode calls...
  1457.  
  1458. However, just to be on the safe side if you do decide to do it this 
  1459. way, best to check at launch whether 24 or 32-bit addressing is set 
  1460. and warn your user you can run under 32-bit addressing only. [Funny... 
  1461. I wrote a small set of routines which does this exactly, and then some 
  1462. - called Witch Doctor. Look to my web site below if you want to check 
  1463. it out. Look in the Sourcery section. Sorry about the personal plug! I 
  1464. couldn't resist... ^_^]
  1465.  
  1466. -- 
  1467. ->Hiep Dam
  1468. ->http://members.aol.com/starlabs/hiep_page.html
  1469. --
  1470. ->my contribution to the English language:
  1471. "netsexual" (net-sek'shoo-el) n. for some bizarre reason, almost 
  1472. always, a man posing as a woman on the internet.
  1473.  
  1474. +++++++++++++++++++++++++++
  1475.  
  1476. >From matthewf@panix.com (Matthew)
  1477. Date: Mon, 01 Jan 1996 18:30:11 -0500
  1478. Organization: PANIX Public Access Internet and Unix, NYC
  1479.  
  1480. 10-30% seems a little high to me... unless you are using SwapMMUmode
  1481. before and after drawing each sprite seperately instead of as a group.  As
  1482. long as you dont use any system calls in the loop that updates all the
  1483. sprites to the screen there shouldnt be any problems.
  1484.  
  1485. i.e.
  1486.  
  1487. slow:
  1488. - ---
  1489. for sprite=0 to num_of_sprites
  1490.   SwapMMUmode
  1491.   drawsprite_to_screen (sprite)
  1492.   SwapMMUmode
  1493. next
  1494.  
  1495. fast:
  1496. - ---
  1497. SwapMMUmode
  1498. for sprite=0 to num_of_sprites
  1499.   drawsprite_to_screen (sprite)
  1500. next
  1501. SwapMMUmode
  1502.  
  1503. of course for ppc apps you can leave out the SwapMMUmode
  1504.  
  1505. Matthew
  1506.  
  1507. +++++++++++++++++++++++++++
  1508.  
  1509. >From pottier@drakkar.ens.fr (Francois Pottier)
  1510. Date: 2 Jan 1996 10:25:15 GMT
  1511. Organization: Ecole Normale Superieure, Paris
  1512.  
  1513. In article <matthewf-0101961830110001@matthewf.dialup.access.net>,
  1514. Matthew <matthewf@panix.com> wrote:
  1515. >slow:
  1516. >-----
  1517.  
  1518. >fast:
  1519. >-----
  1520.  
  1521. Sure, SwapMMUMode is very slow, so it's important to call it
  1522. as little as possible.
  1523.  
  1524. >of course for ppc apps you can leave out the SwapMMUmode
  1525.  
  1526. As far as I remember, when compiling for PowerPC SwapMMUMode is
  1527. a macro which compiles to nothing, so you can leave it in and there
  1528. is no overheard.
  1529.  
  1530. -- 
  1531. Francois
  1532. pottier@dmi.ens.fr
  1533. http://www.eleves.ens.fr:8080/home/pottier/
  1534.  
  1535. ---------------------------
  1536.  
  1537. End of C.S.M.P. Digest
  1538. **********************
  1539.